/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * lab2.java
 *
 * Created on 02.12.2011, 11:39:50
 */
package ecolabs.labs.lab2;

import ecolabs.EcolabsView;
import ecolabs.labs.ScreenJPanel;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Павел
 */
public class Lab2JPanel extends ScreenJPanel {

    class Variant {

        public double Hp;
        public double V;
        public double v0;
    }    
    private Variant data = new Variant();
    private HashMap<Integer, Variant> variants = new HashMap<Integer, Variant>();

    /** Creates new form lab2 */
    /** Creates new form Lab1JPanel */
    public Lab2JPanel(EcolabsView parent) {
        super(parent);
        initComponents();
        Title = "Лабораторная работа №2";
        Caption = "Расчёт пенного пылеуловителя";
        labDatabaseFileName = "LabVariants_№2.txt";
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel3 = new javax.swing.JPanel();
        chartPanel1 = new ecolabs.ChartPanel();
        chartPanel2 = new ecolabs.ChartPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jComboBoxVar = new javax.swing.JComboBox();
        jLabelVar = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabelv2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabelSp = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabelP = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldHp = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldV = new javax.swing.JTextField();
        jTextFieldv0 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setOpaque(false);
        jPanel3.setLayout(new java.awt.GridBagLayout());

        chartPanel1.setName("chartPanel1"); // NOI18N

        javax.swing.GroupLayout chartPanel1Layout = new javax.swing.GroupLayout(chartPanel1);
        chartPanel1.setLayout(chartPanel1Layout);
        chartPanel1Layout.setHorizontalGroup(
            chartPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 528, Short.MAX_VALUE)
        );
        chartPanel1Layout.setVerticalGroup(
            chartPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 312, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 50;
        gridBagConstraints.ipady = 50;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        jPanel3.add(chartPanel1, gridBagConstraints);

        chartPanel2.setName("chartPanel2"); // NOI18N

        javax.swing.GroupLayout chartPanel2Layout = new javax.swing.GroupLayout(chartPanel2);
        chartPanel2.setLayout(chartPanel2Layout);
        chartPanel2Layout.setHorizontalGroup(
            chartPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 528, Short.MAX_VALUE)
        );
        chartPanel2Layout.setVerticalGroup(
            chartPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 312, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 50;
        gridBagConstraints.ipady = 50;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        jPanel3.add(chartPanel2, gridBagConstraints);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecolabs.EcolabsApp.class).getContext().getResourceMap(Lab2JPanel.class);
        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 4, 0);
        jPanel3.add(jLabel9, gridBagConstraints);

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setToolTipText(resourceMap.getString("jLabel10.toolTipText")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 4, 0);
        jPanel3.add(jLabel10, gridBagConstraints);

        jComboBoxVar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        jComboBoxVar.setName("jComboBoxVar"); // NOI18N
        jComboBoxVar.setOpaque(false);
        jComboBoxVar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxVarItemStateChanged(evt);
            }
        });

        jLabelVar.setText(resourceMap.getString("jLabelVar.text")); // NOI18N
        jLabelVar.setName("jLabelVar"); // NOI18N

        jPanel4.setMaximumSize(new java.awt.Dimension(508, 636));
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setOpaque(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setOpaque(false);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabelv2.setText(resourceMap.getString("jLabelv2.text")); // NOI18N
        jLabelv2.setName("jLabelv2"); // NOI18N
        jLabelv2.setRequestFocusEnabled(false);

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabelSp.setText(resourceMap.getString("jLabelSp.text")); // NOI18N
        jLabelSp.setName("jLabelSp"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabelP.setText(resourceMap.getString("jLabelP.text")); // NOI18N
        jLabelP.setName("jLabelP"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 33, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabelP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelSp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelv2, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabelv2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSp, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabelP))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setOpaque(false);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldHp.setText(resourceMap.getString("jTextFieldHp.text")); // NOI18N
        jTextFieldHp.setMaximumSize(new java.awt.Dimension(36, 20));
        jTextFieldHp.setName("jTextFieldHp"); // NOI18N
        jTextFieldHp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldKeyReleased(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldV.setText(resourceMap.getString("jTextFieldV.text")); // NOI18N
        jTextFieldV.setMaximumSize(new java.awt.Dimension(36, 20));
        jTextFieldV.setName("jTextFieldV"); // NOI18N
        jTextFieldV.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldKeyReleased(evt);
            }
        });

        jTextFieldv0.setText(resourceMap.getString("jTextFieldv0.text")); // NOI18N
        jTextFieldv0.setMaximumSize(new java.awt.Dimension(36, 20));
        jTextFieldv0.setName("jTextFieldv0"); // NOI18N
        jTextFieldv0.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldHp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldv0, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldV, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                .addGap(41, 41, 41))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldv0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldHp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setIcon(resourceMap.getIcon("jLabel6.icon")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabelVar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxVar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelVar)
                            .addComponent(jComboBoxVar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(7, 7, 7)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Точки графика для первого размера частиц
     */
    HashMap<Double, Double> points1 = new HashMap<Double, Double>();
    /**
     * Точки графика для второго размера частиц
     */
    HashMap<Double, Double> points2 = new HashMap<Double, Double>();
    ArrayList<XYSeries> serieses1 = new ArrayList<XYSeries>();
    ArrayList<XYSeries> serieses2 = new ArrayList<XYSeries>();
    JFreeChart chart1;
    JFreeChart chart2;

    @Override
    public void ScreenInit() {
        super.ScreenInit();
        loadVariants();
        Execute();
    }

private void jTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldKeyReleased
    Execute();
}//GEN-LAST:event_jTextFieldKeyReleased

private void jComboBoxVarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxVarItemStateChanged
   Variant var;
    try {
        int varNum = Integer.parseInt(jComboBoxVar.getSelectedItem().toString());
        var = variants.get(varNum);
    } catch (Exception e) {
        return;
    }
    jTextFieldHp.setText(Double.toString(var.Hp));
    jTextFieldV.setText(Double.toString(var.V));
    jTextFieldv0.setText(Double.toString(var.v0));
    Execute();
}//GEN-LAST:event_jComboBoxVarItemStateChanged

    public double η(double dt, double Hp, double v2) {
        return Math.abs(100 * (1 - 87.1 * (1.37 * Math.pow(dt, 0.1))) / (Math.pow(Hp, 0.9) * Math.pow(v2, 0.25))); //менять все три и строить график 3 шт    
    }

    /**
     * Вычисляет точки кривой
     * @param Dsol
     * @return 
     */
    public HashMap<Double, Double> Calculate_dt(double dt, double Hp, double v2, double dH) {
        HashMap<Double, Double> points = new HashMap<Double, Double>();
        for (double H = 0; H <= dt; H += dH) {
            points.put(H, η(H, Hp, v2));
        }

        return points;
    }

    public HashMap<Double, Double> Calculate_v(double dt, double Hp, double v2, double dH) {
        HashMap<Double, Double> points = new HashMap<Double, Double>();
        for (double H = 1; H <= v2; H += dH) {
            points.put(H, η(dt, Hp, H));
        }

        return points;
    }

    /**
     * Вычисляет все 3 кривых на одном графике
     * @param Dsol
     * @return 
     */
    public CombinedDomainXYPlot createChart_d(double V, double Hp) {
        CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
                new NumberAxis("η(d)"));
        double v20 = Double.parseDouble(jTextFieldv0.getText());
        ArrayList<Double> Dh2os = new ArrayList<Double>();
        double s = Double.parseDouble(jTextFieldV.getText()) / (3600 * v20); //Площадь сечения корпуса аппарата 
        double D0 = Math.sqrt(4 * s / 3.14); //диаметр корпуса аппарата
        double v2 = v20 * D0 * D0 / 2.25;

        XYSeriesCollection dataset = new XYSeriesCollection();

        XYSeries series = new XYSeries(1);

        HashMap<Double, Double> points = Calculate_dt(30 * Math.pow(10, -5), Hp, v2, Math.pow(10, -5));

        for (Double H : points.keySet()) {
            series.add(H, points.get(H));
        }

        dataset.addSeries(series);

        XYItemRenderer renderer = new StandardXYItemRenderer();
        XYPlot subplot = new XYPlot(dataset, null, new NumberAxis(null), renderer);
        plot.add(subplot);
        return plot;
    }

    /**
     * Вычисляет все 3 кривых на одном графике
     * @param Dsol
     * @return 
     */
    public CombinedDomainXYPlot createChart_v(double V, double Hp, double v) {
        CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
                new NumberAxis("η(v)"));
        //ArrayList<Double> Dh2os = new ArrayList<>();

        double v20 = Double.parseDouble(jTextFieldv0.getText());
        double s = Double.parseDouble(jTextFieldV.getText()) / (3600 * 3); //Площадь сечения корпуса аппарата 
        double D0 = Math.sqrt(4 * s / 3.14); //диаметр корпуса аппарата
        double v2 = v20 * D0 * D0 / 2.25;
        double dt = 5 * Math.pow(10, -5);

        XYSeriesCollection dataset = new XYSeriesCollection();

        XYSeries series = new XYSeries(1);

        HashMap<Double, Double> points = Calculate_v(dt, Hp, v, 0.1);

        for (Double H : points.keySet()) {
            series.add(H, points.get(H));
        }

        dataset.addSeries(series);

        XYItemRenderer renderer = new StandardXYItemRenderer();
        XYPlot subplot = new XYPlot(dataset, null, new NumberAxis(null), renderer);
        plot.add(subplot);
        return plot;
    }

    private void Execute() {
        try {
            //data.Vaq = Double.parseDouble(jTextFieldVaq.getText());
            //data.Va = Double.parseDouble(jTextFieldVa.getText());
            //data.ησ = Double.parseDouble(jTextFieldησ.getText());

            double v20 = Double.parseDouble(jTextFieldv0.getText());
            double s = Double.parseDouble(jTextFieldV.getText()) / (3600 * 3); //Площадь сечения корпуса аппарата 
            double D0 = Math.sqrt(4 * s / 3.14); //диаметр корпуса аппарата
            double v2 = v20 * D0 * D0 / 2.25;//действительная скорость газа в сечении аппарата 
            jLabelv2.setText(String.format("%6.2f", v2));
            // Живое сечение дырчатой решетки S p вычисляем при высоте слоя пены 100 мм, диаметре отверстий 5 мм и плотности жидкости 1000 кг/м3
            double Sp = 1.37 * Math.pow(v2, 0.458) * Math.pow(1, 0.152) / (Math.pow(0.1, 0.61) * Math.pow(0.005, 0.085) * Math.pow(1000, 0.61));
            jLabelSp.setText(String.format("%6.2f", Sp));
            //действительная высотa слоя пены 
            //double Hp = 4.8 * Math.pow(v2, 0.79) * Math.pow(0.05,0.2)/(Math.pow(0.005,0.14) * Math.pow(Sp,1.9) );
            double Hp = Double.parseDouble(jTextFieldHp.getText());
            double Pp = 1.28 * v2 * v2 * 1.02 / (2 * Sp);
            double Pn = 0.447 * Hp * 1000 * 9.81 / Math.sqrt(v2);
            double P6 = 4 * 0.063 / 0.005;
            double Pa = 27 * v2 * v2 * 1.02 / 2;
            //полное гидравлическое сопротивление аппарата
            double P = Pp + Pn + P6 + Pa;
            jLabelP.setText(String.format("%6.2f", P));

            chart1 = new JFreeChart(createChart_d(Double.parseDouble(jTextFieldV.getText()), Hp));
            chart2 = new JFreeChart(createChart_v(Double.parseDouble(jTextFieldV.getText()), Hp, 5));
            chart1.removeLegend();
            chart2.removeLegend();
            chartPanel1.setChart(chart1);
            chartPanel2.setChart(chart2);
            parentFrame.setStatus("Расчёты произведены");
        } catch (Exception e) {
            parentFrame.setStatus("Ошибка при расчётах");
        }
    }

    @Override
    public void export(File file) {
        super.export(file);
                try {
            BufferedImage image1 = chart1.createBufferedImage(500, 500);
            BufferedImage image2 = chart2.createBufferedImage(500, 500);
            File imageFile1 = new File(file.getParent()+"\\chart1Lab2.png");
            File imageFile2 = new File(file.getParent()+"\\chart2Lab2.png");
            ImageIO.write(image1, "png", imageFile1);
            ImageIO.write(image2, "png", imageFile2);
            
            String htmlText = String.format("<html>"
                    + "<head><title>%s</title>"
                    + "</head>"
                    + "<body><center>"
                    + "<h3>Исходные данные:</h3>"
                    + "Общий расход газа = %s<br>"
                    + "Скорость газа в сечении аппарата = %s<br>"
                    + "Высота слоя пены = %s<br>"
                    + "<h3>Результаты:</h3>"
                    + "Действительная скорость газа в сечении аппарата = %s<br>"
                    + "Живое сечение дырчатой решетки = %s<br>"
                    + "Полное гидравлическое сопротивление аппарата = %s<br>"
                    + "<h3>График зависимости эффективности от диаметра корпуса аппарата:</h3>"
                    + "<br><img src=chart1Lab2.png></img><br>"
                    + "<h3>График зависимости эффективности от скорости газа:</h3>"
                    + "<br><img src=chart2Lab2.png></img><br>"
                    + "</center></body> "
                    + "</html>", 
                    Title + ". " + Caption,
                    jTextFieldV.getText(),
                    jTextFieldv0.getText(),
                    jTextFieldHp.getText(),
                    jLabelv2.getText(),
                    jLabelSp.getText(),
                    jLabelP.getText());
            
            // Создаём поток записи
            FileWriter fileWriter = new FileWriter(file);
            PrintWriter printWriter = new PrintWriter(fileWriter, true);
            printWriter.print(htmlText);
            fileWriter.close();
            printWriter.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Загрузка вариантов
     */
    public void loadVariants() {
        jComboBoxVar.setModel(new DefaultComboBoxModel());
        ArrayList<String[]> lines = ScreenJPanel.loadVariants(labDatabaseFileName, 4);
        Variant v;
        int varNum;
        for (String[] parameters : lines) {
            try {
                v = new Variant();
                varNum = Integer.parseInt(parameters[0].trim());
                v.Hp = Double.parseDouble(parameters[1].trim());
                v.V = Double.parseDouble(parameters[2].trim());
                v.v0 = Double.parseDouble(parameters[3].trim());
            } catch (Exception e) {
                // Произошла ошибка??
                // Да ну её к чёёёёёёёёрту!
                // Пойдём я тебе лучше пааааасеку покажу
                parentFrame.setStatus("Ошибка при обработке файла с вариантами в строке " + (lines.indexOf(parameters) + 1));
                continue;
            }
            variants.put(varNum, v);
            jComboBoxVar.addItem(varNum);
        }
        jComboBoxVarItemStateChanged(null);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ecolabs.ChartPanel chartPanel1;
    private ecolabs.ChartPanel chartPanel2;
    private javax.swing.JComboBox jComboBoxVar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelP;
    private javax.swing.JLabel jLabelSp;
    private javax.swing.JLabel jLabelVar;
    private javax.swing.JLabel jLabelv2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField jTextFieldHp;
    private javax.swing.JTextField jTextFieldV;
    private javax.swing.JTextField jTextFieldv0;
    // End of variables declaration//GEN-END:variables
}
